//
//  CourseListAskCell.m
//  xpkc
//
//  Created by TopSage on 15/11/6.
//  Copyright (c) 2015年 TopSage. All rights reserved.
//

#import "CourseListAskCell.h"

@interface CourseListAskCell ()



@end

@implementation CourseListAskCell{
    CGRect content_frame_ask;
    CGRect content_bg_frame_ask;
    CGRect head_frame_ask;
    CGRect name_frame_ask;
    CGRect content_frame_replay;
    CGRect content_bg_frame_replay;
    CGRect head_frame_replay;
    CGRect name_frame_replay;
    
    CGFloat offsize;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatView];
    }
    return self;
}

- (void)creatView{
    
    self.backgroundColor = CCOLOR;
    offsize = 0.04*SCREEN_WIDTH;
    
    content_bg_frame_ask    = CGRectMake(offsize, offsize, SCREEN_WIDTH-offsize*2-55, 60);
    content_frame_ask       = CGRectMake(offsize*2, offsize*1.5, SCREEN_WIDTH-offsize*4-55, 60);
    head_frame_ask          = CGRectMake(SCREEN_WIDTH-offsize-40, offsize, 40, 40);
    name_frame_ask          = CGRectMake(SCREEN_WIDTH-offsize-45, offsize+40, 55, 30);
    
    content_bg_frame_replay = CGRectMake(offsize+55, offsize, SCREEN_WIDTH-offsize*2-55, 60);
    content_frame_replay    = CGRectMake(offsize*2+55, offsize*1.5, SCREEN_WIDTH-offsize*4-55, 60);
    head_frame_replay       = CGRectMake(offsize, offsize, 40, 40);
    name_frame_replay       = CGRectMake(offsize, offsize+40, 55, 40);
    
    self.contentBG = [[UIImageView alloc]initWithFrame:content_bg_frame_ask];
    UIImage *imgask = [UIImage imageNamed:@"talkbox_white"];
    imgask = [imgask stretchableImageWithLeftCapWidth:100 topCapHeight:70];
    self.contentBG.image = imgask;
    [self addSubview:self.contentBG];
    
    self.contentLabel = [[UILabel alloc]initWithFrame:content_frame_ask];
    self.contentLabel.numberOfLines = 0;
    self.contentLabel.lineBreakMode = NSLineBreakByCharWrapping;
    [self addSubview:self.contentLabel];
    
    self.headImgView = [[UIImageView alloc]initWithFrame:head_frame_ask];
    self.headImgView.image = [UIImage imageNamed:@"portrait"];
    self.headImgView.layer.borderWidth = 2;
    self.headImgView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.headImgView.layer.cornerRadius = 20;
    self.headImgView.clipsToBounds = YES;
    [self addSubview:self.headImgView];
    
    self.userName = [[UILabel alloc]initWithFrame:name_frame_ask];
    self.userName.textColor = [UIColor darkGrayColor];
    self.userName.textAlignment = NSTextAlignmentCenter;
    self.userName.font = [UIFont systemFontOfSize:14];
    self.userName.numberOfLines = 0;
    self.userName.lineBreakMode = NSLineBreakByCharWrapping;
    [self addSubview:self.userName];
}

- (void)setQuestionStyle:(QuestionStyle)questionStyle{
    switch (questionStyle) {
        case QuestionStyleAsk:
        {
            self.contentBG.left = content_bg_frame_ask.origin.x;
            UIImage *imgask = [UIImage imageNamed:@"talkbox_white"];
            imgask = [imgask stretchableImageWithLeftCapWidth:imgask.size.width/2 topCapHeight:imgask.size.height/2];
            self.contentBG.image = imgask;
            self.contentLabel.left = content_frame_ask.origin.x;
            self.headImgView.frame = head_frame_ask;
            self.userName.frame = name_frame_ask;
        }
            break;
        case QuestionStyleReply:
        {
            self.contentBG.left = content_bg_frame_replay.origin.x;
            UIImage *imgreplay = [UIImage imageNamed:@"talkbox_green"];
            imgreplay = [imgreplay stretchableImageWithLeftCapWidth:imgreplay.size.width/2 topCapHeight:imgreplay.size.height/2];
            self.contentBG.image = imgreplay;
            self.contentLabel.left = content_frame_replay.origin.x;
            self.headImgView.frame = head_frame_replay;
            self.userName.frame = name_frame_replay;
        }
            break;
            
        default:
            break;
    }
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
